RequireScript('characters.js');

data = {
	font: GetSystemFont(),
	win: GetSystemWindowStyle(),
	characters: characters,
	fps: 12,
	background: 'background.rmp',
	maps: {MetorVille: 'MeteorVille.rmp'}
}

getNames = function(cs){
	r = new Array();
	for (c in cs){
		r.push(cs[c].name);
	}
	return r;
}

getName = function(item, array){
	for (a in array){
		if (item == array[a].name){
			return array[a];
		}
	}
}

game = function(){
	RequireScript('play.js');
	RequireScript('menu.js');
	RequireScript('keys.js');
	on = function(key){
		return 'isPressed('+key+')';
	}
	c = Menu({win: data.win,
						font: data.font,
						arrow: LoadImage('arrow.png'),
						events: [[on(KEY_HOME), HOME], [on(KEY_PAGEUP),HOME],
										 [on(KEY_END), END],[on(KEY_PAGEDOWN), END],[on(KEY_ESCAPE), END],
										 [on(KEY_UP),UP],[on(KEY_LEFT),UP],[on(KEY_BACKSPACE),UP],[on(KEY_SHIFT),UP],[on(KEY_W), UP],[on(KEY_A),UP],
												[on(KEY_NUM_8),UP][on(KEY_NUM_4),UP],[on(KEY_SLASH),UP],[on(KEY_PERIOD),UP],[on(MOUSE_RIGHT),UP],
										 [on(KEY_DOWN),DOWN],[on(KEY_RIGHT),DOWN],[on(KEY_S),DOWN],[on(KEY_D),DOWN],[on(KEY_X),DOWN],[on(KEY_NUM_2),DOWN],
												[on(KEY_NUM_6),DOWN], [on(KEY_TAB),DOWN],[on(KEY_PERIOD),DOWN],[on(KEY_MINUS),DOWN],[on(MOUSE_MIDDLE),DOWN],
										 [on(ENTER), KEY_ENTER],[on(ENTER), KEY_SPACE],[on(ENTER), KEY_CTRL],[on(ENTER), KEY_NUM_5],[on(ENTER), MOUSE_LEFT]],
						x: 0,
						y: 0,
						wx: 16,
						wy: 8,
						winwidth: 60,
						textheight: 16,
						borderwidth: 10,
						bgwidth: 60,
						bgheight: 200,
						current: 1,
						items: getNames(data.characters),
						run: true})
	
	character = getName(characters, c);
	
	character.events = []
	
	Play(data.maps.MeteorVille, data.fps, [character]);
}